package com.cms.stu.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cms.stu.entity.StudentEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cms.stu.entity.ClassEntity;
import com.cms.stu.service.ClassService;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.R;



/**
 * 
 *
 * @author weixiaochun
 * @email xiaochun0121@163.com
 * @date 2022-03-15 10:53:38
 */
@RestController
@RequestMapping("stu/class")
public class ClassController {
    @Autowired
    private ClassService classService;

    /**
     * 查询新生入校的班级
     */
    @RequestMapping("/studentByClassAndNew")
    //@RequiresPermissions("stu:class:list")
    public R studentByClassAndNew(){
        List<StudentEntity> newStudents = classService.studentByClassAndNew();

        return R.ok().put("newStudents", newStudents);
    }

    /**
     * 根据年级查找班级
     */
    @RequestMapping("/listByGrade")
    //@RequiresPermissions("stu:class:list")
    public R listByGrade(@RequestParam String grade){
        List<ClassEntity> classes = classService.listByGrade(grade);

        return R.ok().put("classes", classes);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("stu:class:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("stu:class:info")
    public R info(@PathVariable("id") Long id){
		ClassEntity classes = classService.getById(id);

        return R.ok().put("class", classes);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("stu:class:save")
    public R save(@RequestBody ClassEntity classes){
		classService.save(classes);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("stu:class:update")
    public R update(@RequestBody ClassEntity classes){
		classService.updateById(classes);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("stu:class:delete")
    public R delete(@RequestBody Long[] ids){
		classService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
